package com.wwg.widget.fake;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class FakeBoxView extends View {
    @Nullable
    private Bitmap mContent;
    private final Paint mPaint;

    public FakeBoxView(Context context) {
        this(context, null);
    }

    public FakeBoxView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FakeBoxView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public FakeBoxView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);

        mPaint = new Paint();
    }

    public void drawBitmap(Bitmap bitmap) {
        mContent = bitmap;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (mContent != null) {
            canvas.drawBitmap(mContent, 0, 0, mPaint);
        }
    }
}
